import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import moment from 'moment';
import { fileupload } from '/@/api/sys/upload';
import { userSimple, projectSimple, getdistinctUser } from '/@/api/backs/foundation/foundation';

export const columns: BasicColumn[] = [
  {
    title: '人员名称',
    dataIndex: 'userName',
  },
  {
    title: '是否打卡',
    dataIndex: 'isRecord',
    customRender: ({ record }) => {
      if (record.isRecord) {
        return '否';
      } else {
        return '是';
      }
    },
  },
  {
    title: '人员类型',
    dataIndex: 'infoType',
    customRender: ({ record }) => {
      if (record.informationDO) {
        if (record.informationDO.infoType == 2) {
          return '外聘';
        }else {
          return '内聘';
        }

      } else {
        return '--';
      }
    },
  },
  {
    title: '离职时间',
    dataIndex: 'leaveTime',
    sorter: true,
    customRender: ({ record }) => {
      const time = record.leaveTime;
      return time ? moment(time * 1000).format('YYYY-MM-DD') : '-';
    },
  },
];
let a = 0
export const searchFormSchema: FormSchema[] = [
  {
    field: 'userId',
    label: '人员名称',
    component: 'Select',
    colProps: { span: 8 },
  },
  {
    field: 'infoType',
    label: '人员类型',
    component: 'Select',
    colProps: { span: 8 },
    componentProps: {
      placeholder: '请选择',
      options: [
        {
          value: '3',
          label: '内聘'
        },
        {
          value: '2',
          label: '外聘'
        }
      ]
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '项目名称',
    component: 'InputNumber',
    ifShow: false,
  },
  {
    field: 'name',
    label: '项目名称',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
  },
  {
    field: 'typeAll',
    label: '项目类型',
    component: 'Select',
    dynamicDisabled: true,
    required: true,
    componentProps: {
      placeholder: '请选择项目类型',
      labelInValue: true,
    },
  },


  {
    field: 'planStartTime',
    label: '计划开始时间',
    component: 'DatePicker',
    dynamicDisabled: true,
    required: true,
    componentProps: {
      valueFormat: 'X',
    },
  },
  {
    field: 'planEndTime',
    label: '计划结束时间',
    dynamicDisabled: true,
    component: 'DatePicker',
    required: true,
    componentProps: (values) => {
      return {
        valueFormat: 'X',
      };
    },
  },
  {
    field: 'directorName',
    label: '负责人',
    component: 'Input',
    dynamicDisabled: true,
    required: true,
  },
  {
    field: 'directorMobile',
    label: '负责人电话',
    dynamicDisabled: true,
    component: 'InputNumber',
    rules: [
      {
        required: true,
        // @ts-ignore
        validator: async (rule, value) => {
          const phoneReg = /^1[34578]\d{9}$$/;
          if (!phoneReg.test(value) && value) {
            /* eslint-disable-next-line */
            return Promise.reject('请输入正确的手机号');
          }
          return Promise.resolve();
        },
        trigger: 'change',
      },
    ],
  },
  {
    field: 'effectGraphFileUrl',
    label: '效果图',
    component: 'Upload',
    required: true,
    componentProps: {
      api: fileupload,
      emptyHidePreview: true,
      maxNumber: 1,
      disabled: true,
      maxSize: 10,
      accept: ['image/*'],
      placeholder: '请上传效果图',
    },
    rules: [
      {
        required: true,
        validator: async (rule, value) => {
          if (!value) {
            return Promise.reject('请上传效果图');
          }
        },
        trigger: 'change',
      },
    ],
  },
  {
    field: 'planarGraphFileUrl',
    label: '平面图',
    component: 'Upload',
    required: true,
    componentProps: {
      api: fileupload,
      emptyHidePreview: true,
      maxNumber: 1,
      maxSize: 10,
      disabled: true,
      accept: ['image/*'],
      placeholder: '请上传平面图',
    },
    rules: [
      {
        required: true,
        validator: async (rule, value) => {
          if (!value) {
            return Promise.reject('请上传平面图');
          }
        },
        trigger: 'change',
      },
    ],
  },
  {
    field: 'address',
    label: '地址',
    component: 'Input',
    required: true,
    slot: 'addressShow',
    colProps: { lg: 12, md: 12 },
  },
  {
    field: 'constructUnit',
    label: '施工单位',
    dynamicDisabled: true,
    component: 'Input',
  },
  {
    field: 'workUnit',
    label: '建设单位',
    dynamicDisabled: true,
    component: 'Input',
  },
  {
    field: 'superviseUnit',
    label: '监理单位',
    dynamicDisabled: true,
    component: 'Input',
  },
  {
    field: 'designUnit',
    label: '设计单位',
    dynamicDisabled: true,
    component: 'Input',
  },
  {
    field: 'surveyUnit',
    dynamicDisabled: true,
    label: '勘察单位',
    component: 'Input',
  },
  {
    field: 'simpleDescription',
    label: '项目简介',
    dynamicDisabled: true,
    component: 'InputTextArea',
    colProps: { lg: 24, md: 24 },
  },
];
export const drawerFormSchema: FormSchema[] = [
  {
    field: 'list',
    label: '人员信息',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      if (formModel.projectAll) {
        return {
          api: getdistinctUser,
          labelField: 'nickname',
          mode: 'multiple',
          valueField: 'id',
          placeholder: '请选择人员',
          labelInValue: true,
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
          },
          params: { projectId: formModel.projectAll ? formModel.projectAll.value : null },
        };
      }
    },
  },
  {
    field: 'projectAll',
    label: '项目信息',
    component: 'ApiSelect',
    required: true,
    colProps: { lg: 24, md: 24 },
    // colProps: { span: 8 },
    componentProps: {
      api: projectSimple,
      labelField: 'name',
      valueField: 'id',
      placeholder: '请选择项目',
      labelInValue: true,
    },
    dynamicDisabled: true,
  },
  {
    field: 'type',
    label: '人员类型',
    component: 'RadioGroup',
    colProps: { span: 8 },
    required: true,
    componentProps: {
      options: [
        {
          label: '管理员',
          value: 0,
        },
        {
          label: '施工员',
          value: 1,
        },
      ],
    },
  },
  {
    field: 'isRecord',
    label: '是否需要打卡',
    component: 'RadioGroup',
    colProps: { span: 8 },
    required: true,
    componentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  // {
  //   field: 'leaveTime',
  //   label: '离开时间',
  //   required: true,
  //   component: 'DatePicker',
  //   componentProps: {
  //     valueFormat: 'X',
  //   },
  //   ifShow: ({ values }) => (values.status == 1 ? false : true),
  // },
];
